<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="推送客户" prop="customer">
        <el-input
          v-model="queryParams.customer"
          placeholder="请输入推送客户"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="推送类型" prop="pushType">
        <el-select v-model="queryParams.pushType" placeholder="请选择推送类型" clearable>
          <el-option
            v-for="dict in dict.type.t_interfaces_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="数据状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择数据状态" clearable>
          <el-option
            v-for="dict in dict.type.t_interfaces_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="推送时间" prop="pushTime">-->
<!--        <el-date-picker clearable-->
<!--                        v-model="queryParams.pushTime"-->
<!--                        type="date"-->
<!--                        value-format="yyyy-MM-dd"-->
<!--                        placeholder="请选择推送时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->

      <el-form-item label="推送时间">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']"
        ></el-date-picker>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['snowRemoving:interfaces:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="interfacesList" @selection-change="handleSelectionChange">
      <el-table-column label="编号" lign="center" type="index" />
      <el-table-column label="推送客户" align="center" prop="customer" />
      <el-table-column label="推送时间" align="center" prop="pushTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.pushTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="推送类型" align="center" prop="pushType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.t_interfaces_type" :value="scope.row.pushType"/>
        </template>
      </el-table-column>
      <el-table-column label="数据状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.t_interfaces_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="推送内容" align="center" prop="pushInfo" />

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document"
            @click="handleSelect(scope.row)"
            v-hasPermi="['snowRemoving:interfaces:edit']"
          >推送详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 详情对话框 -->
    <el-dialog :title="title" :visible.sync="open"  width="800px" append-to-body>

      <el-table v-loading="loading" :data="interfacesDetail" @selection-change="handleSelectionChange">
        <el-table-column label="编号" lign="center" type="index" />
        <el-table-column label="推送路段" align="center" prop="pushRoad" />

        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-document"
              @click="expandSelect(scope.row)"
              v-hasPermi="['snowRemoving:interfaces:edit']"
            >展开</el-button>
          </template>
        </el-table-column>
<!--        <el-table-column label="推送内容" align="center" prop="pushInfo" />-->
<!--              <el-table-column label="上级id" align="center" prop="parentId" />-->
      </el-table>
      <pagination
        v-show="total2>0"
        :total="total2"
        :page.sync="queryParams2.pageNum"
        :limit.sync="queryParams2.pageSize"
        @pagination="SelectDetail()"
      />
    </el-dialog>




    <!--天气数据的抽屉-->
    <el-drawer
      title="路段信息详情"
      :visible.sync="table"
      direction="rtl"
      size="50%">
      <el-table :data="ExpandDetail">
        <el-table-column property="time" label="日期" width="300"></el-table-column>
        <el-table-column property="temperature" label="温度" width="300"></el-table-column>
        <el-table-column property="weatherCode" label="天气代码"></el-table-column>
      </el-table>
    </el-drawer>


    <!--天气事件的抽屉-->
    <el-drawer
      title="天气事件详情"
      :visible.sync="tableEvent"
      direction="rtl"
      size="50%">
      <el-table :data="ExpandEventDetail">
        <el-table-column property="eventCode" label="事件编码" width="150"></el-table-column>
        <el-table-column property="eventType" label="事件类型" width="150"></el-table-column>
        <el-table-column property="eventLevel" label="事件等级" width="150"></el-table-column>
        <el-table-column property="volume" label="预测值" ></el-table-column>
        <el-table-column property="remark" label="备注" ></el-table-column>
      </el-table>


      <el-divider>详情数据</el-divider>
      <el-descriptions class="margin-top"  :column="3"  border>

        <el-descriptions-item :labelStyle="{ 'width': '95px' }"  :contentStyle="{ 'width': '160px' }">
          <template slot="label" >
            <i class="el-icon-user"></i>
            事件编码
          </template>
          {{pushData.eventCode}}
        </el-descriptions-item >
        <el-descriptions-item :labelStyle="{ 'width': '100px' }">
          <template slot="label">
            <i class="el-icon-mobile-phone"></i>
            事件类型
          </template>
          {{pushData.eventType}}
        </el-descriptions-item>


        <el-descriptions-item>
          <template slot="label" >
            <i class="el-icon-map-location"></i>
            开始桩号
          </template>
          {{pushData.startStake}}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-place"></i>
            详情桩号
          </template>
          {{pushData.monitorCode}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-aim"></i>
            预测值
          </template>
          {{pushData.volume}}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-map-location"></i>
            结束桩号
          </template>
          {{pushData.endStake}}
        </el-descriptions-item>


        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-collection-tag"></i>
            事件等级
          </template>
          {{pushData.eventLevel}}级
        </el-descriptions-item>


        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            推送方
          </template>
          {{pushData.source}}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-watch"></i>
            开始时间
          </template>
          {{pushData.forecastStartTime}}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-watch"></i>
            结束时间
          </template>
          {{pushData.forecastEndTime}}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-chat-dot-square"></i>
            备注
          </template>
          {{pushData.remark}}
        </el-descriptions-item>





      </el-descriptions>

    </el-drawer>



  </div>
</template>

<script>
import { listInterfaces, getInterfaces, getExpand, getEventExpand } from "@/api/snowRemoving/interfaces";

export default {
  name: "Interfaces",
  dicts: ['t_interfaces_status', 't_interfaces_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      parentId : null,
      pushData: {},
      // 日期范围
      dateRange: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      total2: 0,
      // 数据管理表格数据
      interfacesList: [],
      interfacesDetail: [],
      ExpandDetail: [],
      ExpandEventDetail: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 抽屉显示弹出层
      table: false,
      tableEvent: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        customer: null,
        pushType: null,
        status: null,
        pushTime: null,
        pushRoad: null,
        parentId: null
      },
      queryParams2: {
        pageNum: 1,
        pageSize: 10,
        customer: null,
        pushType: null,
        status: null,
        pushTime: null,
        pushRoad: null,
        parentId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询数据管理列表 */
    getList() {
      this.loading = true;
      listInterfaces(this.addDateRange(this.queryParams,this.dateRange)).then(response => {
        this.interfacesList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        customer: null,
        pushType: null,
        status: null,
        pushTime: null,
        pushRoad: null,
        parentId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.dateRange = [];
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加数据管理";
    },
    /** 查询数据详情 */
    handleSelect(row) {
      this.reset();
      this.total2 = 1
      const id = row.id
      this.parentId = row.id
      getInterfaces(id).then(response => {
        this.open = true;
        this.interfacesDetail = response.rows;
        this.total2 = response.total;
        this.loading = false;
        this.title = "推送数据详情";
      });
    },

    /** 分页数据详情 */
    SelectDetail() {
      this.reset();
      this.queryParams2.parentId= this.parentId
      listInterfaces(this.queryParams2).then(response => {
        this.open = true;
        this.interfacesDetail = response.rows;
        this.total2 = response.total;
        this.loading = false;
        this.title = "推送数据详情";
      });
    },

    /** 展开数据详情 */
    expandSelect(row) {
      const id = row.id || this.ids
      const pushType = row.pushType
      if (pushType ===0 ){
        getExpand(id).then(response => {
          this.table = true;
          this.ExpandDetail = response.rows;
        });
      }else {
        getEventExpand(id).then(response => {
          this.tableEvent = true;
          this.ExpandEventDetail = response.rows;
          this.pushData = this.ExpandEventDetail[0]
        });
      }
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('snowRemoving/interfaces/export', {
        ...this.queryParams
      }, `interfaces_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style scoped  lang="scss">


.text-box{

  width: 768px;
  height: 50px;
  margin-top: 200px
  //text-align: center; //文本对齐方式


}

.data-box{
  box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 2px 4px rgba(0, 0, 0, .04);
  width: 768px;
  height: 300px;

}


</style>
